<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    function draw() {
      var ctx = document.getElementById('canvas').getContext('2d')
      for (var i=0; i<3; i++) {
        for (var j=0; j<3; j++) {
          ctx.save()
          ctx.fillStyle = `rgb(${ 51 * i}, ${255 - 51 * i}, 255)`
          ctx.translate(10 + 50 * j, 10 + 50 * i)
          ctx.fillRect(0, 0, 25, 25)
          ctx.restore()
        }
      }
    }
  </script>
</head>
<body onload="draw()">
  <canvas id="canvas" width="150" height="150"></canvas>
</body>
</html>